# -*- coding: utf-8 -*-
"""
@Time    : 2024/7/10 10:55 
@Author  : ZhangShenao 
@File    : 2.通过bind解决RunnableLambda传递多参数问题.py 
@Desc    : 通过bind解决RunnableLambda传递多参数问题

所有的Runnable组件,在调用时只能接收一个参数
可以通过bind()函数,传递多个参数
"""
import random

from langchain_core.runnables import RunnableLambda


def get_weather(city: str, district: str, unit: str) -> str:
    """
    获取天气
    :param city: 市
    :param district: 区
    :param unit: 温度单位
    :return: 温度
    """

    print(f'city: {city}, district: {district}, unit: {unit}')
    temperature = random.randint(10, 30)
    return f'{city}市{district}区的温度为: {temperature} {unit}'


# 通过bind()函数,提前向Runnable传递多个参数
runnable_lambda = RunnableLambda(get_weather).bind(district='昌平', unit='摄氏度')
result = runnable_lambda.invoke('北京')
print(result)
